import {
	BASE_URL,
	commonParams,
} from '@/env';

const install = (Vue, vm) => {
	Vue.prototype.$u.http.setConfig({
		baseUrl: BASE_URL,
		loadingText:'请稍后...',
		
	});
	Vue.prototype.$u.http.interceptor.request = (config) => {
		const token = uni.getStorageSync('userId') || '';
		if(token){
			 config.data.userid_locked=token;
		};
		//携带公共参数
		if(uni.getStorageSync('userId')){
			config.data.uid =  uni.getStorageSync('uid'); 			
		} 
		config.data={...config.data,...commonParams};
		// config.header.token = token;
		return config; 
	}
	Vue.prototype.$u.http.interceptor.response = (res) => {
	
		if(res.code == 403 ||  res.code == 404 || res.code == 500 || res.code == 503 ){
			this.$utils.modal({
				title: '温馨提示',
				content: '网络繁忙，请稍后重试！',
				showCancel: false
			});
		}else{
			return res;
		}
		// if(res.code == 200) {
		// 	return res.data;  
		// } else return false;
	}
}
export default {
	install
}